* Article: Countering Misperceptions to Reduce Prejudice: An Experiment on 
* Attitudes toward Muslim Americans
* Author: Scott Williamson
* Code File for Analysis in Article and Online Appendix
* File also constructs dataset used to build plots
* For questions, please email scottrw630@gmail.com

*************************
*************************
** Main Paper Analysis **
*************************
*************************

* Load "Muslim_Prejudice_Data_SRW.dta"

**********************
** Prepping Dataset **
**********************

**** Age:

* Fix obvious errors in birthyear 
replace birthyr = "" if birthyr == "PA"
replace birthyr = "" if birthyr == "CA"
replace birthyr = "" if birthyr == "Cali"
replace birthyr = "" if birthyr == "TX"
replace birthyr = "" if birthyr == "USA"
replace birthyr = "" if birthyr == "PR"
replace birthyr = "" if birthyr == "Tenn"
replace birthyr = ""  if birthyr == "Us"
replace birthyr = ""  if birthyr == "wa"
replace birthyr = "1959"  if birthyr == "2959"
replace birthyr = "19"  if birthyr == "I 19"
replace birthyr = "19"  if birthyr == "197p"
replace birthyr = "1960"  if birthyr == "1o60"
* Destring
destring birthyr, replace
* Convert birthyear to age.
gen age = .
replace age = 2017-birthyr if birthyr >=1900 & birthyr <=2015
replace age = birthyr if birthyr <110
replace age = . if age<18

**** Drop Speeders

* Speeders were defined as respondents who completed the survey in one half
* the median survey time.
summarize(duration), detail
* Median = 787
drop if duration < 393.5

**** Generate Treatment Variable

* Treatment variable named "information"
* Combining base and shame treatments for single information treatment
generate information = 1 if treatment==1|treatment==2
replace information = 0 if treatment==0

**** Creating Covariate Variables

* Respondents who do not know Muslims:
generate not_know_muslim = 1 if srw_muslim==2
replace not_know_muslim = 0 if srw_muslim==1
* Respondents who identified themselves as white:
generate white = 1 if race==1
replace white = 0 if race!=1
* Gender
generate male = 1 if gender==1
replace male = 0 if gender==2
* Construction of elderly dummy variables
summarize(age),detail
generate old = 1 if age>59&age!=.
replace old = 0 if age<60&age!=.
generate old2 = 1 if age>64&age!=.
replace old2 = 0 if age<65&age!=.
* Respondents who identified themselves as Republicans:
generate republican = 1 if pid_main==2
replace republican = 0 if pid_main!=2&pid_main!=.
* Respondents who identified themselves as ideological conservatives:
generate conservative = 1 if ideology==4|ideology==5
replace conservative = 0 if conservative!=1&ideology!=.
* Creating numerical survey identifiers for the three surveys:
egen survey_id = group(survey)

**** Creating Outcome Variables

* Feeling Thermometer
generate therm = srw_therm_1 if srw_therm_1!=.
replace therm = srw_therm_2 if srw_therm_2!=.
* Patriotism Outcome
generate patriotism = 1 if srw_pat==1|srw_pat==2
replace patriotism = 0 if srw_pat==3
* Surveillance
generate surveillance = srw_policy_h_1
* Refugee Ban
generate refugee_ban = srw_policy_h_2
* Registration
generate registration = srw_policy_h_3
* PCA
pca therm patriotism srw_policy*
predict pca_attitudes, score
summarize pca_attitudes

**** Creating Robustness Check Variables
* Dummy variable for respondents exposed to the political correctness license:
generate pc_license = 1 if srw_therm_2!=.
replace pc_license = 0 if srw_therm_2==.
* Dummy variable for respondents exposed to terrorism prime is named "terrorism."

***********************************
** Cronbach's Alpha for Outcomes **
***********************************

alpha therm patriotism srw_policy*, std item

****************************************
** Learned From Information Treatment **
****************************************

**** How many respondents acknowledged surprise at the different statements
**** about Muslim Americans?

* Constructing variable for first statement on sports:
generate sports_base = 1 if srw_base_info_h_1==1
replace sports_base = 0 if srw_base_info_h_1==.&treatment==1
generate sports_shame = 1 if srw_shame_info_h_1==1
replace sports_shame = 0 if srw_shame_info_h_1==.&treatment==2
generate sports_surprise = 1 if sports_base==1|sports_shame==1
replace sports_surprise = 0 if sports_surprise!=1&information==1
* Calculating percentage of respondents in treatment group who were surprised
* at sports statement
tabulate sports_surprise

* Constructing variable for second statement on political violence:
generate violence_base = 1 if srw_base_info_h_2==1
replace violence_base = 0 if srw_base_info_h_2==.&treatment==1
generate violence_shame = 1 if srw_shame_info_h_2==1
replace violence_shame = 0 if srw_shame_info_h_2==.&treatment==2
generate violence_surprise = 1 if violence_base==1|violence_shame==1
replace violence_surprise = 0 if violence_surprise!=1&information==1
* Calculating percentage of respondents in treatment group who were surprised
* at political violence statement
tabulate violence_surprise

* Constructing variable for third statement on American identity:
generate american_base = 1 if srw_base_info_h_3==1
replace american_base = 0 if srw_base_info_h_3==.&treatment==1
generate american_shame = 1 if srw_shame_info_h_3==1
replace american_shame = 0 if srw_shame_info_h_3==.&treatment==2
generate american_surprise = 1 if american_base==1|american_shame==1
replace american_surprise = 0 if american_surprise!=1&information==1
* Calculating percentage of respondents in treatment group who were surprised
* at American identity statement
tabulate american_surprise

* Constructing variable for respondents who expressed surprise for at least
* one statement
generate none_base = 1 if srw_base_info_h_4==1
replace none_base = 0 if srw_base_info_h_4==.&treatment==1
generate none_shame = 1 if srw_shame_info_h_4==1
replace none_shame = 0 if srw_shame_info_h_4==.&treatment==2
generate no_surprise = 1 if none_base==1|none_shame==1
replace no_surprise = 0 if no_surprise!=1&information==1
* Calculating percentage of respondents who were surprised
tabulate no_surprise

****************************************************
** Main Effects from Figure 1 and Results Section **
****************************************************

ttest pca_attitudes, by(information)
ttest therm, by(information)
ttest patriotism, by(information)
ttest surveillance, by(information)
ttest refugee_ban, by(information)
ttest registration, by(information)

*******************************************
** Terrorism Prime Results from Figure 2 **
*******************************************

* PCA Outcome
ttest pca_attitudes if terrorism==1, by(information)
ttest pca_attitudes if terrorism==0, by(information)
reg pca_attitudes information##terrorism, vce(robust)

* Feeling Thermometer Outcome
ttest therm if terrorism==1, by(information)
ttest therm if terrorism==0, by(information)
reg therm information##terrorism, vce(robust)

* Patriotism Outcome
ttest patriotism if terrorism==1, by(information)
ttest patriotism if terrorism==0, by(information)
reg patriotism information##terrorism, vce(robust)

* Surveillance Outcome
ttest surveillance if terrorism==1, by(information)
ttest surveillance if terrorism==0, by(information)
reg surveillance information##terrorism, vce(robust)

* Refugee Ban Outcome
ttest refugee_ban if terrorism==1, by(information)
ttest refugee_ban if terrorism==0, by(information)
reg refugee_ban information##terrorism, vce(robust)

* Registration Outcome
ttest registration if terrorism==1, by(information)
ttest registration if terrorism==0, by(information)
reg registration information##terrorism, vce(robust)

**************************************
** PC License Results from Figure 2 **
**************************************

* PCA Outcome
ttest pca_attitudes if pc_license==1, by(information)
ttest pca_attitudes if pc_license==0, by(information)
reg pca_attitudes information##pc_license, vce(robust)

* Feeling Thermometer Outcome
ttest therm if pc_license==1, by(information)
ttest therm if pc_license==0, by(information)
reg therm information##pc_license, vce(robust)

* Patriotism Outcome
ttest patriotism if pc_license==1, by(information)
ttest patriotism if pc_license==0, by(information)
reg patriotism information##pc_license, vce(robust)

* Surveillance Outcome
ttest surveillance if pc_license==1, by(information)
ttest surveillance if pc_license==0, by(information)
reg surveillance information##pc_license, vce(robust)

* Refugee Ban Outcome
ttest refugee_ban if pc_license==1, by(information)
ttest refugee_ban if pc_license==0, by(information)
reg refugee_ban information##pc_license, vce(robust)

* Registration Outcome
ttest registration if pc_license==1, by(information)
ttest registration if pc_license==0, by(information)
reg registration information##pc_license, vce(robust)

*****************************************
** Heterogeneous Results from Figure 3 **
*****************************************

**** Elderly Interaction

* PCA Outcome
reg pca_attitudes information##old pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Thermometer Outcome
reg therm information##old pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Patriotism Outcome
reg patriotism information##old pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Surveillance Outcome
reg surveillance information##old pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information##old pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Registration Outcome
reg registration information##old pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)

**** White Interaction

reg pca_attitudes information##white pc_license not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
* Thermometer Outcome
reg therm information##white pc_license not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
* Patriotism Outcome
reg patriotism information##white pc_license not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
* Surveillance Outcome
reg surveillance information##white pc_license not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information##white pc_license not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
* Registration Outcome
reg registration information##white pc_license not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)

**** Knows No Muslims Interaction

reg pca_attitudes information##not_know_muslim pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Thermometer Outcome
reg therm information##not_know_muslim pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Patriotism Outcome
reg patriotism information##not_know_muslim pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Surveillance Outcome
reg surveillance information##not_know_muslim pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information##not_know_muslim pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Registration Outcome
reg registration information##not_know_muslim pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)

**** Republican Interaction

reg pca_attitudes information##republican pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Thermometer Outcome
reg therm information##republican pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Patriotism Outcome
reg patriotism information##republican pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Surveillance Outcome
reg surveillance information##republican pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information##republican pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)
* Registration Outcome
reg registration information##republican pc_license not_know_muslim white age male educ newsint conserv republican terrorism, vce(robust)

***********************
***********************
** Appendix Analysis **
***********************
***********************

***************************
** Outcome Summary Stats **
***************************

* Table 1 in Appendix

* PCA Outcome
summarize pca_attitudes
* Thermometer Outcome
summarize therm
* Patriotism Outcome
summarize patriotism
* Surveillance Outcome
summarize surveillance
* Refugee Ban Outcome
summarize refugee_ban
* Registration Outcome
summarize registration

***********************
** Random Assignment **
***********************

* Information Treatment (Table 3 in Appendix)
tabulate information
* Information Treatment and Terrorism Prime (Table 4 in Appendix)
tabulate information terrorism
* Information Treatment and Non-PC License (Table 5 in Appendix)
tabulate information pc_license
* All three randomizations together (Table 6 in Appendix)
tabulate information if terrorism==0&pc_license==0
tabulate information if terrorism==0&pc_license==1
tabulate information if terrorism==1&pc_license==0
tabulate information if terrorism==1&pc_license==1

*******************
** Balance Tests **
*******************

**** Information Treatment 

* Logistic Regression (Table 7 in Appendix)
logit information age male white educ newsint conservative republican terrorism not_know_muslim

* Individual Variables (Table 8 in Appendix)
ttest age, by(information)
ttest male, by(information)
ttest white, by(information)
ttest educ, by(information)
ttest newsint, by(information)
ttest terrorism, by(information)
ttest republican, by(information)
ttest conservative, by(information)
ttest not_know_muslim, by(information)
ttest pc_license, by(information)

**** Terrorism Prime

* Logistic Regression (Table 9 in Appendix)
logit terrorism information age male white educ newsint conservative republican not_know_muslim

* Individual Variables (Table 10 in Appendix)
ttest age, by(terrorism)
ttest male, by(terrorism)
ttest white, by(terrorism)
ttest educ, by(terrorism)
ttest newsint, by(terrorism)
ttest conservative, by(terrorism)
ttest republican, by(terrorism)
ttest not_know_muslim, by(terrorism)
ttest information, by(terrorism)

**** Non-PC License 

* Logistic Regression (Table 11 in Appendix)
logit pc_license information age male white educ newsint conservative republican terrorism not_know_muslim

* Individual Variables (Table 12 in Appendix)
ttest age, by(pc_license)
ttest male, by(pc_license)
ttest white, by(pc_license)
ttest educ, by(pc_license)
ttest newsint, by(pc_license)
ttest terrorism, by(pc_license)
ttest republican, by(pc_license)
ttest conservative, by(pc_license)
ttest not_know_muslim, by(pc_license)
ttest information, by(pc_license)

*****************************
** Main Effect Regressions **
*****************************

* Table 13 of Appendix

* PCA Outcome
ttest pca_attitudes, by(information)
* Thremometer Outcome
ttest therm, by(information)
* Patriotism Outcome
ttest patriotism, by(information)
* Surveillance Outcome
ttest surveillance, by(information)
* Refugee Ban Outcome
ttest refugee_ban, by(information)
* Registration Outcome
ttest registration, by(information)

* Table 14 of Appendix

* PCA Outcome
reg pca_attitudes information, vce(robust)
* Thermometer Outcome
reg therm information, vce(robust)
* Patriotism Outcome
reg patriotism information, vce(robust)
* Surveillance Outcome
reg surveillance information, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information, vce(robust)
* Registration Outcome
reg registration information, vce(robust)

********************************
** Robustness of Main Effects **
********************************

**** Speeders Included (Table 15 of Appendix)

preserve
clear
* Reload data (because speeders were dropped previously)
insheet using "SSI_Combined_SRW.csv"
* Reconstruct variables
generate information = 1 if treatment==1|treatment==2
replace information = 0 if treatment==0
generate therm = srw_therm_1 if srw_therm_1!=.
replace therm = srw_therm_2 if srw_therm_2!=.
generate patriotism = 1 if srw_pat==1|srw_pat==2
replace patriotism = 0 if srw_pat==3
generate surveillance = srw_policy_h_1
generate refugee_ban = srw_policy_h_2
generate registration = srw_policy_h_3
pca therm patriotism srw_policy*
predict pca_attitudes, score
** Main Effects Analysis with Speeders
* PCA Outcome
reg pca_attitudes information, vce(robust)
* Thermometer Outcome
reg therm information, vce(robust)
* Patriotism Outcome
reg patriotism information, vce(robust)
* Surveillance Outcome
reg surveillance information, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information, vce(robust)
* Registration Outcome
reg registration information, vce(robust)
restore

**** Covariates Included (Table 16 of Appendix)

reg pca_attitudes information not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
reg therm information not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
reg patriotism information not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
reg surveillance information not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
reg refugee_ban information not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)
reg registration information not_know_muslim age male educ newsint conserv republican terrorism, vce(robust)

**** Individual SSI Surveys 

* SSI Survey I (Table 17 of Appendix)
reg pca_attitudes information if survey_id==1, vce(robust)
reg therm information if survey_id==1, vce(robust)
reg patriotism information if survey_id==1, vce(robust)
reg surveillance information if survey_id==1, vce(robust)
reg refugee_ban information if survey_id==1, vce(robust)
reg registration information if survey_id==1, vce(robust)

* SSI Survey II (Table 18 of Appendix)
reg pca_attitudes information if survey_id==2, vce(robust)
reg therm information if survey_id==2, vce(robust)
reg patriotism information if survey_id==2, vce(robust)
reg surveillance information if survey_id==2, vce(robust)
reg refugee_ban information if survey_id==2, vce(robust)
reg registration information if survey_id==2, vce(robust)

* SSI Survey III (Table 19 of Appendix)
reg pca_attitudes information if survey_id==3, vce(robust)
reg therm information if survey_id==3, vce(robust)
reg patriotism information if survey_id==3, vce(robust)
reg surveillance information if survey_id==3, vce(robust)
reg refugee_ban information if survey_id==3, vce(robust)
reg registration information if survey_id==3, vce(robust)

*************************************
** Heterogenous Effect Regressions **
*************************************

**** Table 20 of Appendix: See Code from Heterogeneous Effects Analysis from
**** main paper, above. 

**********************************
** Construction of Age Variable **
**********************************

**** Table 21 of Appendix:

**** Dummy Variable with cutoff at 65 years
* PCA Outcome
reg pca_attitudes i.information##i.old2 pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Thermometer Outcome
reg therm i.information##i.old2 pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Patriotism Outcome
reg patriotism i.information##i.old2 pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Surveillance Outcome
reg surveillance i.information##i.old2 pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban i.information##i.old2 pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Registration Outcome
reg registration i.information##i.old2 pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)

**** Continuous Age Variable
* PCA Outcome
reg pca_attitudes i.information##c.age pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Thermometer Outcome
reg therm i.information##c.age pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Patriotism Outcome
reg patriotism i.information##c.age pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Surveillance Outcome
reg surveillance i.information##c.age pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban i.information##c.age pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)
* Registration Outcome
reg registration i.information##c.age pc_license not_know_muslim white male educ newsint conserv republican terrorism, vce(robust)

******************************
** Terrorism Prime Analysis **
******************************

**** Main Effects of Terrorism Prime (Table 22 of Appendix)

* PCA Outcome
reg pca_a terrorism, vce(robust)
* Thermometer Outcome
reg therm terrorism, vce(robust)
* Patriotism Outcome
reg patriotism terrorism, vce(robust)
* Surveillance Outcome
reg surveillance terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban terrorism, vce(robust)
* Registration Outcome
reg registration terrorism, vce(robust)

**** Interaction Results with Terrorism Prime (Table 23 of Appendix)

* PCA Outcome
reg pca_a i.information##i.terrorism, vce(robust)
* Thermometer Outcome
reg therm i.information##i.terrorism, vce(robust)
* Patriotism Outcome
reg patriotism i.information##i.terrorism, vce(robust)
* Surveillance Outcome
reg surveillance i.information##i.terrorism, vce(robust)
* Refugee Ban Outcome
reg refugee_ban i.information##i.terrorism, vce(robust)
* Registration Outcome
reg registration i.information##i.terrorism, vce(robust)

**** Information Treatment Effect with Terrorism Prime Subgroup (Table 24 of 
**** Appendix)

* PCA Outcome
reg pca_a information if terrorism==1, vce(robust)
* Thermometer Outcome
reg therm information if terrorism==1, vce(robust)
* Patriotism Outcome
reg patriotism information if terrorism==1, vce(robust)
* Surveillance Outcome
reg surveillance information if terrorism==1, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information if terrorism==1, vce(robust)
* Registration Outcome
reg registration information if terrorism==1, vce(robust)

*****************************
** Non-PC License Analysis **
*****************************

**** Interaction Results with Non-PC License (Table 25 of Appendix)

* PCA Outcome
reg pca_a i.information##i.pc_license, vce(robust)
* Thermometer Outcome
reg therm i.information##i.pc_license, vce(robust)
* Patriotism Outcome
reg patriotism i.information##i.pc_license, vce(robust)
* Surveillance Outcome
reg surveillance i.information##i.pc_license, vce(robust)
* Refugee Ban Outcome
reg refugee_ban i.information##i.pc_license, vce(robust)
* Registration Outcome
reg registration i.information##i.pc_license, vce(robust)

**** Information Treatment Effect with Non-PC License Subgroup (Table 26 of 
**** Appendix)

* PCA Outcome
reg pca_a information if pc_license==1, vce(robust)
* Thermometer Outcome
reg therm information if pc_license==1, vce(robust)
* Patriotism Outcome
reg patriotism information if pc_license==1, vce(robust)
* Surveillance Outcome
reg surveillance information if pc_license==1, vce(robust)
* Refugee Ban Outcome
reg refugee_ban information if pc_license==1, vce(robust)
* Registration Outcome
reg registration information if pc_license==1, vce(robust)

******************************
** Prejudice Prime Analysis **
******************************

**** Creating Dummy for Information Treatment with No Prejudice Prime
generate base_treat = 1 if treatment==1
replace base_treat = 0 if base!=1

**** Creating Dummy for Information Treatment with Prejudice Prime
generate shame_treat = 1 if treatment==2
replace shame_treat = 0 if shame!=1

**** Analysis of Main Effects with Both Treatment Groups (Table 27 of Appendix)

* PCA Outcome
reg pca_attitudes i.base i.shame, vce(robust)
* Thermometer Outcome
reg therm i.base i.shame, vce(robust)
* Patriotism Outcome
reg patriotism i.base i.shame, vce(robust)
* Surveillance Outcome
reg surveillance i.base i.shame, vce(robust)
* Refugee Ban Outcome
reg refugee_ban i.base i.shame, vce(robust)
* Registration Outcome
reg registration i.base i.shame, vce(robust)

***************************
***************************
** Create Data for Plots **
***************************
***************************

* The following code outputs the spreadsheet used to construct Figures 1 in the paper.

*preserve
*keep terrorism pc_license information surveillance refugee_ban registration therm pca_attitudes
*outsheet using "Williamson_JEPS_Figure1_Data.csv",comma 
*restore

*********************
** End of Document **
*********************
